package demo5;

public class Test8 {
    public static void main(String[] args) {
        Thread t= new Thread(()->{
            while(true) {
                System.out.println("线程开始");
                try {
                    Thread.sleep(1000);
                } catch (InterruptedException e) {
                    throw new RuntimeException(e);
                }
                System.out.println("线程结束");
            }
        }," 新线程");


        // isAlive() : 这个方法是查看某个线程是否存活
        System.out.println(t.isAlive());
        // 这里将线程t修改成后台线程: 跟随前台线程一起结束
        t.setDaemon(true);

        t.start();


        System.out.println(t.isAlive());


        try {
            Thread.sleep(1000);
        } catch (InterruptedException e) {
            throw new RuntimeException(e);
        }

        System.out.println(t.isAlive());
    }
}
